﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Diagnostics;

public partial class index : System.Web.UI.Page
{
    //creamos el dataset que contendra las tablas
    DataSet ds = new DataSet();

    protected void Page_Load(object sender, EventArgs e)
    {

        
            CounterCreationDataCollection contador = new CounterCreationDataCollection();
            if (!PerformanceCounterCategory.Exists("ContratoOnline"))
            {
            CounterCreationData ventas = new CounterCreationData("ContratoOnline",
                "monitoreo de las ventas en linea de la empresa",
            PerformanceCounterType.NumberOfItems32);           

            contador.Add(ventas);
            
                PerformanceCounterCategory.Create("ContratoOnline", "ContratoOnline", contador);
            }
    }
    
    protected void btnimguser_Click(object sender, ImageClickEventArgs e)
    {
        PerformanceCounter pc = new PerformanceCounter("ContratoOnline", "ContratoOnline", false);
        
        try
        {
            if (txtuser.Text.Trim() != "")
            {
                Usuarios.Usuario us = new Usuarios.Usuario();
                ds = us.Login(txtuser.Text, txtclave.Text);
                DataTable Tus = ds.Tables["USUARIOS"];

                lblaviso.Visible = false;
                lblbien.Visible = true;



                if (ds.Tables["USUARIOS"].Rows.Count > 0)
                {

                    

                    pc.IncrementBy(5);
                    string uxyz6, ngws, thkn;
                    uxyz6 = Tus.Rows[0]["IDUSUARIO"].ToString().Trim();
                    ngws = Tus.Rows[0]["NOMBRECOMPLETO"].ToString().Trim();
                    thkn = Tus.Rows[0]["TIPO"].ToString().Trim();
                    lblbien.Text = "BienVenido " + ngws;
                    Session["iduser"] = uxyz6;
                    Session["Ncom"] = ngws;
                    if (thkn == "Candidato")
                    {
                        Response.Redirect("Candidato.aspx");

                    }
                    else if (thkn == "Empresa")
                    {
                        Response.Redirect("Empresa.aspx");
                    }
                    else if (thkn == "Outsourcing")
                    {
                        Response.Redirect("OutSourcing.aspx");
                    }
                }
                else
                {
                    EventLog LogErri = new EventLog();
                    if (!EventLog.SourceExists("WebContrataci"))
                    {
                        EventLog.CreateEventSource("WebContrataci", "Application");
                        LogErri.Source = "WebContrataci";
                        LogErri.WriteEntry("Usuario no registrado " + txtuser.Text, EventLogEntryType.Information, 1);
                    }
                    else
                    {

                        LogErri.Source = "WebContrataci";
                        LogErri.WriteEntry("Usuario no registrado " + txtuser.Text);
                    }
                    lblaviso.Visible = true;
                    lblbien.Visible = false;

                }

            }
            else
            {
                EventLog LogErri = new EventLog();
                if (!EventLog.SourceExists("WebContrataci"))
                {
                    EventLog.CreateEventSource("WebContrataci", "Application");
                    LogErri.Source = "WebContrataci";
                    LogErri.WriteEntry("Usuario no registrado" + txtuser.Text, EventLogEntryType.Information, 1);
                }
                else
                {

                    LogErri.Source = "WebContrataci";
                    LogErri.WriteEntry("Usuario no registrado" + txtuser.Text);
                }
                lblaviso.Visible = true;
                lblbien.Visible = false;
            }
        }
        catch (Exception ex)
        {
            lblaviso.Text = "No se puede, intente mas tarde";
            lblaviso.Visible = true;
            lblbien.Visible = false;


                EventLog LogErr = new EventLog();
                if (!EventLog.SourceExists("WebContrataci"))
                {
                    EventLog.CreateEventSource("WebContrataci", "Application");
                    LogErr.Source = "WebContrataci";
                    LogErr.WriteEntry(ex.ToString(),EventLogEntryType.Information, 1);
                }
                else
                {

                    LogErr.Source = "WebContrataci";
                    LogErr.WriteEntry(ex.ToString());
                }
            
        }
    }   

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Session.Clear();
        Session.Abandon();

    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Session.Clear();
        Session.Abandon();


    }

}